/**
 * Font selector plugin
 * turns an ordinary input field into a list of web-safe fonts
 * Usage: $('select').fontSelector();
 *
 * Author     : James Carmichael
 * Website    : www.siteclick.co.uk
 * License    : MIT
 */
jQuery.fn.fontSelector = function() {
 
    var fonts ={
        'Amazone':'amazone',
        'Ambrosia':'ambrosia',
        'Beautiful Caps':'beautiful_caps',
        'Camellia':'camellia',
        'Dinh Tran':'dinh_tran',
        'Floral':'floral',
        'Isadora':'isadora',
        'Isadora Bold':'isadora_bold',
        'Marlboro':'marlboro',
        'Niagara':'niagara',
        'Scriptina KT':'scriptina_kt',
        'Thu Phap':'thu_phap',
        'Wedding KT':'wedding_kt' 
    };
 
    return this.each(function(){
 
        // Get input field
        var sel = this;
 
        // Add a ul to hold fonts
        var ul = $('<ul class="fontselector"></ul>');
        $('body').prepend(ul);
        $(ul).hide();
 
        jQuery.each(fonts, function(key,value) {
            $(ul).append('<li><a href="#" class="'+value+'"  style="font-family: ' + value + '">' + key.split(',')[0] + '</a></li>');
 
        // Prevent real select from working
            
        });
        $(ul).find('a').click(function() {
            var font = $(this).css('font-family');
            var fontName = $(this).html();
            $(sel).find('#sbSelector').html(fontName);
            $(sel).find('#sbSelector').attr('rel',font);
            $('#background').find('.text_active').css('font-family',font);
            $(ul).hide();
            return false;
        });
        $(sel).click(function() {
 
            //ev.preventDefault();
            // Show font list
            $(ul).toggle();
           
            // Position font list
            $(ul).css({
                top:  $(sel).offset().top + $(sel).height() + 4,
                left: $(sel).offset().left
            });
 
            // Blur field
            //$(this).blur();
            return false;
        });
    });
   
}